package priv.pront.code.national.acwing.base;

import java.util.Scanner;

public class A843_N皇后问题 {

    static char[][] g;
    static boolean[] col, dg, udg;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        g = new char[n][n];
        col = new boolean[n];
        dg = new boolean[20];
        udg = new boolean[20];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                g[i][j] = '.';

        dfs(0);
    }

    private static void dfs(int u) {
        if (u == g.length) {
            for (char[] c : g) {
                System.out.println(c);
            }
            return;
        }
        for (int i = 0; i < g.length; i++) {
            if (!col[i] && !dg[u + i] && !udg[g.length - u + i]) { // 截距相同为同一条对角线
                g[u][i] = 'Q';
                col[i] = dg[u + i] = udg[g.length - u + i] = true;
                dfs(u + 1);
                col[i] = dg[u + i] = udg[g.length - u + i] = false;
                g[u][i] = '.';
            }
        }
    }
}
